package service

import (
	"context"
	__ "driver_srv/basic/driverproto"
	"driver_srv/handler/dao"
	"errors"
	"order_srv/handler/models"
)

// CreateBusRoute 创建线路
func (s *Server) CreateRoute(_ context.Context, in *__.CreateRouteReq) (*__.CreateRouteResp, error) {
	rout, err := dao.CreateRout(in)
	if err != nil {
		return nil, errors.New("创建线路失败" + err.Error())
	}
	return &__.CreateRouteResp{Id: rout.Id}, nil
}

// CreateBusSite 创建站点
func (s *Server) CreateSite(_ context.Context, in *__.CreateSiteReq) (*__.CreateSiteResp, error) {
	site, err := dao.CreateSite(in)
	if err != nil {
		return nil, errors.New("创建站点失败" + err.Error())
	}
	return &__.CreateSiteResp{Id: site.Id}, nil
}

// ListSite 站点列表
func (s *Server) ListSite(_ context.Context, in *__.ListSiteReq) (*__.ListSiteResp, error) {
	listSite, err := dao.ListSite(in)
	if err != nil {
		return nil, errors.New("查询站点列表失败" + err.Error())
	}
	return &__.ListSiteResp{List: listSite}, nil
}

// CreateRideRecord 创建用户乘车
func (s *Server) CreateRideRecord(_ context.Context, in *__.CreateRideRecordReq) (*__.CreateRideRecordResp, error) {
	record, err := dao.CreateRideRecord(in)
	if err != nil {
		return nil, errors.New("创建用户乘车失败" + err.Error())
	}
	return &__.CreateRideRecordResp{Id: record.Id}, nil
}
// 创建Ar
func (s *Server) CreateAr(_ context.Context, in *__.CreateArReq) (*__.CreateArResp, error) {
	var ar models.Ar
	if err := ar.Create(); err != nil {
		return nil, errors.New("创建Ar失败" + err.Error())
	}
	ar = models.Ar{
		Name:      in.Name,
		Age:       int32(in.Age),
		Address:   in.Address,
	}
}
